using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WindowsLive.Writer.Api;

namespace InsertVideo
{
    public partial class frmOptions : Form
    {
        private bool isenabled;
        private int width;
        private int option;
        VideoSettings _settings;

        public frmOptions(VideoSettings settings)
        {
            InitializeComponent();
            _settings = settings;
            setOptions();
        }

        private void setOptions()
        {
            width = _settings.DefaultWidth;
            option = _settings.DefaultOption;
            isenabled = _settings.IsEnabled;
            chOpenNewWindow.Checked = _settings.DefaultOpen;
            chTransparency.Checked = _settings.DefaultTransparancySetting;
            chbxAutoplay.Checked = _settings.DefaultAutoplay;
            nupWidth.Value = width;
            if (isenabled)
            {
                rbEnabledYes.Checked = true;
                rbEnabledNo.Checked = false;
                nupWidth.Enabled = true;
                label2.Enabled = true;
            }
            else
            {
                rbEnabledNo.Checked = true;
                rbEnabledYes.Checked = false;
                nupWidth.Enabled = false;
                label2.Enabled = false;
            }
            switch (option)
            {
                case 0:
                    rbEmbed.Checked = true;
                    break;
                case 1:
                    rbImage.Checked = true;
                    break;
                case 2:
                    rbPlugin.Checked = true;
                    break;
            }
            chPreview.Checked = _settings.Preview;
            chTitle.Checked = _settings.DefaultTitleIsEnabled;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (rbEnabledNo.Checked == true)
            {
                _settings.IsEnabled = false;
            }
            else
            {
                _settings.IsEnabled = true;
                _settings.DefaultWidth = (int)nupWidth.Value;
            }

            if (rbEmbed.Checked == true)
                _settings.DefaultOption = 0;
            else if (rbImage.Checked == true)
                _settings.DefaultOption = 1;
            else if (rbPlugin.Checked == true)
                _settings.DefaultOption = 2;
            _settings.DefaultTransparancySetting = chTransparency.Checked;
            _settings.Preview = chPreview.Checked;
            _settings.DefaultOpen = chOpenNewWindow.Checked;
            _settings.DefaultTitleIsEnabled = chTitle.Checked;
            _settings.DefaultAutoplay = chbxAutoplay.Checked;
            this.Close();
        }

        private void CheckedChanged(object sender, EventArgs e)
        {
            if (rbEnabledNo.Checked == true)
            {
                nupWidth.Enabled = false;
                label2.Enabled = false;
            }
            else
            {
                nupWidth.Enabled = true;
                label2.Enabled = true;
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            frmThanks thanks = new frmThanks();
            thanks.ShowDialog();
        }

    }
}